#!/bin/sh
#
# Wrapper which (almost) silently restarts the VM in case of segfaults.

error_counter=0;
error_occured=139
while [ ${error_counter} -le 50 -a ${error_occured} -eq 139 ]; do
    echo "Running JamVM-initial: ${@}"
    jamvm-initial ${1+"$@"}
    error_occured=$?
    if [ ${error_occured} -eq 139 ]; then
        echo "JamVM-initial crashed - silently trying again"
        error_counter=$(( $error_counter + 1 ))
    fi
done

exit ${error_occured}
